<div class="purchases index">
    <div id="filtro_busqueda" class="filtro">
        <fieldset>
            <legend>Busqueda</legend>
            <?php echo $form->create('Purchase', array('url' => array('controller' => 'purchases', 'action' => 'index'))); ?>
            <?php
            $fecha_fin = date('d/m/Y');
            echo $form->input('desde', array('label' => 'Desde', 'type' => 'text'));
            echo $form->input('hasta', array('label' => 'Hasta', 'type' => 'text', 'default' => $fecha_fin));
            echo $form->submit(__('Buscar', true));
            echo $form->end();
            ?>
        </fieldset>
    </div>
    <h2><?php echo $html->image('iconos/purchases.png');
            __('Compras'); ?></h2>

    <table cellpadding="0" cellspacing="0">
        <tr>
<!--			<th><?php echo $this->Paginator->sort('Id', 'id'); ?></th>-->
            <th><?php echo $this->Paginator->sort('Fecha de Compra', 'purchase_date'); ?></th>
            <th><?php echo $this->Paginator->sort('Cantidad', 'purchase_amount'); ?></th>
            <th><?php echo $this->Paginator->sort('Artículo', 'article_id'); ?></th>
            <th><?php echo $this->Paginator->sort('Proveedor', 'supplier_id'); ?></th>
            <th><?php echo $this->Paginator->sort('Pedido', 'order_id'); ?></th>
            <th class="actions"><?php __('Opciones'); ?></th>
        </tr>
        <?php
        $i = 0;
        foreach ($purchases as $purchase):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            ?>
            <tr<?php echo $class; ?>>
    <!--		<td><?php echo $purchase['Purchase']['id']; ?>&nbsp;</td>-->
                <td><?php
            $fecha = date('d/m/Y', strtotime($purchase['Purchase']['purchase_date']));
            echo $fecha;
            ?>&nbsp;</td>
                <td><?php echo $purchase['Purchase']['purchase_amount']; ?>&nbsp;</td>
                <td>
                    <?php echo $this->Html->link($purchase['Article']['mark'] . '-' . $purchase['Article']['model'], array('controller' => 'articles', 'action' => 'view', $purchase['Article']['id'])); ?>
                </td>
                <td>
                    <?php echo $this->Html->link($purchase['Supplier']['name'], array('controller' => 'suppliers', 'action' => 'view', $purchase['Supplier']['id'])); ?>
                </td>
                <td>
                    <?php
                    if ($purchase['Purchase']['order_id'] != NULL) {
                        $fecha = date('d/m/Y', strtotime($purchase['Order']['date']));
                        echo $this->Html->link($fecha, array('controller' => 'orders', 'action' => 'view', $purchase['Order']['id']));
                    } else {
                        $fecha = 'Carga Inicial';
                        echo $fecha;
                    }
                    ?>
                </td>
                <td class="actions">
                    <?php echo $this->Html->link(__('Ver', true), array('action' => 'view', $purchase['Purchase']['id'])); ?>
                    <?php echo $this->Html->link(__('Editar', true), array('action' => 'edit', $purchase['Purchase']['id'])); ?>
    <?php echo $this->Html->link(__('Eliminar', true), array('action' => 'delete', $purchase['Purchase']['id']), null, sprintf(__('Esta seguro que desea eliminar la compra # %s?', true), date('d/m/Y', strtotime($purchase['Purchase']['purchase_date'])))); ?>
                </td>
            </tr>
<?php endforeach; ?>
    </table>
    <p>
        <?php
        echo $this->Paginator->counter(array(
            'format' => __('Página %page% de %pages%, mostrando %current% registros de %count% en total, a partir del registro %start%, terminando en el %end%', true)
        ));
        ?>	</p>

    <div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('anterior', true), array(), null, array('class' => 'disabled')); ?>
        | 	<?php echo $this->Paginator->numbers(); ?>
        |
<?php echo $this->Paginator->next(__('siguiente', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
    </div>
</div>
<!--<div class="actions">
        <h3><?php __('Actions'); ?></h3>
        <ul>
                <li><?php echo $this->Html->link(__('New Purchase', true), array('action' => 'add')); ?></li>
                <li><?php echo $this->Html->link(__('List Articles', true), array('controller' => 'articles', 'action' => 'index')); ?> </li>
                <li><?php echo $this->Html->link(__('New Article', true), array('controller' => 'articles', 'action' => 'add')); ?> </li>
        </ul>
</div>-->
<script type="text/javascript">
    (function($){
        // Date picker
        $('#PurchaseDesde').datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        
        //toda la documentacion de esta librería la encontras aca
        //http://jqueryui.com/demos/datepicker/
    })(jQuery);
</script>
<script type="text/javascript">
    (function($){
        // Date picker
        $('#PurchaseHasta').datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        
        //toda la documentacion de esta librería la encontras aca
        //http://jqueryui.com/demos/datepicker/
    })(jQuery);
</script>